<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>推送消息到ios和android</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/jquery.min.js"></script>
    <link rel="icon"  type="image/x-icon"  href="/bdtlaw/messagesp/index/static/assets/img/favicon.ico">
    <link rel="apple-touch-icon-precomposed" href="/bdtlaw/messagesp/index/static/assets/i/app-icon72x722x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <script src="/bdtlaw/messagesp/index/static/assets/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/bdtlaw/messagesp/index/static/assets/css/amazeui.min.css" />

    <link rel="stylesheet" href="/bdtlaw/messagesp/index/static/assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet"href="/bdtlaw/messagesp/index/static/assets/css/app.css">
    <script src="/bdtlaw/messagesp/index/static/assets/js/jquery.min.js"></script>


    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/bdtlaw/messagesp/index/static/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/bdtlaw/messagesp/index/static/assets/css/amazeui.datatables.min.css"/>
    <link rel="stylesheet" href="/bdtlaw/messagesp/index/static/assets/css/app.css"/>


    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/amazeui.min.js"></script>
    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/amazeui.datatables.min.js"></script>
    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/app.js"></script>
    <!--<script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/theme.js}"></script>-->
    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/json2.js"></script>
    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/My97DatePicker/WdatePicker.js"></script>
    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/My97DatePicker/calendar.js"></script>
    <script type="application/javascript" src="/bdtlaw/messagesp/index/static/assets/js/layer/layer.js"></script>
    <style type="text/css">
        .addCustom_box {
            position: relative;
            height: 30px;
            margin-bottom: 10px;
        }

        .addCustom {
            display: inline-block;
            height: 20px;
            /*background: url(/bdtlaw/messagesp/index/static/assets/img/addbtn.png) no-repeat 0 2px;*/
            padding-left: 22px;
            font-size: 13px;
            color: #156cd0;
            text-decoration: underline;
            cursor: pointer;
            margin: 10px 0 0 20px;
        }

        .cancel_extra {
            width: 22px;
            height: 22px;
            /*background: url(/bdtlaw/messagesp/index/static/assets/img/cancel.png) no-repeat;*/
            display: inline-block;
            vertical-align: middle;
            margin-left: 10px;
            cursor: pointer;
        }


    </style>
    <script type="application/javascript">
        $(window).load(function() {
            $("#radiopush0").prop("checked",true);
            $("#time").css('display','none');
            $("#startTime").val('');
            $("#expireTime").val('');
        });


        function addExtra()
        {
            var extraE = $("#extra1>input[type=text]");

            var extraSize = extraE.size();
            if(extraSize>20)
            {
                alert("最多添加10个自定义参数");
                return;
            }

            $("#extra1").append('<input type="text" style="width:500px;display:inline-block;float:right;margin:0 20px  ;"  placeholder="value"  />'
                    + '<input type="text" style="width:500px;display:inline-block;float:right;margin:0 20px  ;"   placeholder="key"/>'
                    + '<span class="cancel_extra" style="float: right;margin:10px  ;" onclick="delExtra(this);" ></span>');

        }


        function delExtra(o){
            o.id="del";

            var input1 = $("#del").prev();
            var input2=input1.prev();

            input2.remove();
            input1.remove();
            o.remove();


            var spanV = $("#extra1>span");

        }

        function submitForm()
        {

            /*var extraE = $("#extra1>input[type=text]");
             var arr = [];
             var extraSize = extraE.size();

             for (var i = 0; i < extraSize; i += 2) {
             var key = 'key' + i;
             var value = 'value' + i;
             var number = i + 1;

             key = $("#extra1 input:eq(" + i + ")").val();
             value = $("#extra1 input:eq(" + number + ")").val();
             var extra = new Object();
             extra.extraKey = key;
             extra.extraValue = value;
             arr.push(extra);
             }*/
            var arr = [];

            var extra1 = new Object();
            var extra2 = new Object();
            var extraVale1 = $("#extraTitle").val();
            extra1.extraKey="title";
            extra1.extraValue=extraVale1;
            var extraVale2 = $("#extraUrl").val();
            extra2.extraKey="url";
            extra2.extraValue=extraVale2;
            arr.push(extra1);
            arr.push(extra2);


            var title = $("#title").val();
            /*var description = $("#description").val();*/
            var text = $("#text").val();
            var startTime=$("#startTime").val();
            var expireTime=$("#expireTime").val();
            if(text.length>400){
                layer.msg("最多输入400字");
                return false;

            }
            if( title==null || title==""){
                layer.msg("标题必填，请填写！");
                return false;

            }
            if( text==null || text==""){
                layer.msg("内容必填，请填写！");
                return false;

            }


            var extraJson = arr;
            var broadCast = new Object();
            broadCast.title = title;
            /*broadCast.description = description;*/
            broadCast.text = text;
            broadCast.extraJson = extraJson;
            broadCast.expireTime=expireTime;
            broadCast.startTime=startTime;
            /* $.ajax({
             url: "push",
             type: "POST",
             contentType: 'application/json',
             data: JSON.stringify(broadCast),
             success: function (data)
             {

             if (data.status==200) {
             alert("消息发送成功!");
             location.reload();
             } else {
             alert("消息发送失败!");
             }
             }
             })*/


            layer.msg('你确定提交消息推送吗？', {
                shade: [0.8, '#393D49'],
                time: 0 //不自动关闭
                ,btn: ['确定', '取消']
                ,yes: function(index){
                    $.ajax({
                        url:"/bdtlaw/messagesp/index/push",
                        data:JSON.stringify(broadCast),
                        type:"POST",
                        contentType: 'application/json',
                        success:function(data){
                            if (data.status==200) {
                                layer.msg("消息发送成功!");
                                location.reload();
                            } else {
                                layer.msg("消息发送失败!");
                            }

                        }
                    });

                    layer.close(index);

                }
            });
        }

        /**
         * 判断消息推送时间：立即推送、定时推送
         */
        function divClick()
        {
            var show="";
            var apm = document.getElementsByName("apps");
            for(var i=0;i<apm.length;i++){
                if(apm[i].checked)
                    show = apm[i].value;
            }

            switch (show){
                case '1':
                    $("#time").css('display','none');
                    $("#startTime").val('');
                    $("#expireTime").val('');
                    break;
                case '2':
                    $("#time").css('display','block');
                    break;
                default:
                    $("#time").style.display = "none";
                    $("#startTime").val('');
                    $("#expireTime").val('');
                    break;
            }

        }

        function textdown(e)
        {
            textevent = e ;
            if(textevent.keyCode == 8)
            {
                return;
            }
            if(document.getElementById('text').value.length >= 400)
            {
                layer.msg("最多输入400个字");
                if(!document.all)
                {
                    textevent.preventDefault();
                }
                else
                {
                    textevent.returnValue = false;
                }
            }
        }
        function textup()
        {

            var s = document.getElementById('text').value;
            document.getElementById('textcount').textContent=s.length;

            //判断ID为text的文本区域字数是否超过400个
            if(s.length > 400)
            {
                document.getElementById('text').value=s.substring(0,400);
            }
        }




    </script>
</head>

<body data-type="index">
<script src="/bdtlaw/messagesp/index/static/assets/js/theme.js"></script>
<div class="am-g tpl-g">
      <header>
          <div class="am-fr tpl-header-navbar">
              <ul>
                  <li class="am-text-sm tpl-header-navbar-welcome">
                      <a href="javascript:;">欢迎你, <span>中央编办事业发展中心</span> </a>
                  </li>
              <li class="am-text-sm" >
              <a href="/bdtlaw/messagesp/index/logout">
                  <span class="am-icon-sign-out"></span> 退出
              </a>
          </li>
                  </ul>
              </div>
      </header>

    <!-- 侧边导航栏 -->
    <div class="left-sidebar">
        <!-- 用户信息 -->
        <div class="">
            <div class="tpl-user-panel-slide-toggleable" style="text-align:center;">
                <div class="tpl-user-panel-profile-picture" style="margin: 0 auto;">
                    <img src="/bdtlaw/messagesp/index/static/assets/img/user04.png" alt="">
                </div>
                <span class="user-panel-logged-in-text">
              <i class="am-icon-circle-o am-text-success tpl-user-panel-status-icon"></i>
              中央编办事业发展中心
          </span>
            </div>
        </div>

        <!-- 菜单 -->
        <ul class="sidebar-nav">
            <!--<li class="sidebar-nav-link">
                <a href="index.html" class="active">
                    <i class="am-icon-home sidebar-nav-link-logo"></i> 首页
                </a>
            </li>-->
            <li class="sidebar-nav-link" style="padding: 20px;">
                <a href="/bdtlaw/messagesp/index">
                    <i class="am-icon-wpforms sidebar-nav-link-logo"></i>消息推送

                </a>
            </li>



        </ul>
    </div>

    <div class="">
        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">


            <div class="row">

                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf" style="text-align:center;line-height: 20px;">
                            <h1><span style="vertical-align:-100%">推送消息到Android和IOS</span></h1>

                        </div>
                        <div class="widget-body am-fr">

                            <form action="/push" method="post" class="am-form tpl-form-border-form tpl-form-border-br">

                                <!--<div class="am-form-group">
                                    <label th:for="description" class="am-u-sm-3 am-form-label">消息描述：</label>
                                    <div class="am-u-sm-9">
                                        <input type="text" autocomplete="off"  class="tpl-form-input" name="description" id="description"
                                               placeholder="用于标识消息，方便管理和查找"/>
                                    </div>
                                </div>
    -->


                                <div class="am-form-group">

                                    <label for="title" class="am-u-sm-3 am-form-label"> 标题:</label>

                                    <div class="am-u-sm-9">
                                        <input type="text"autocomplete="off"  class="tpl-form-input" name="title" id="title"/>

                                    </div>

                                </div>


                                <div class="am-form-group">
                                    <label for="text" class="am-u-sm-3 am-form-label">内容:</label>
                                    <div class="am-u-sm-9">
                                        <textarea class=""autocomplete="off"  rows="10" onKeyDown="textdown(event)" onKeyUp="textup()" name="text" id="text" style="resize: none;"  placeholder="最多输入400字"></textarea>
                                        <p><span id="textcount">0</span>/400</p>
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <label for="extraTitle" class="am-u-sm-3 am-form-label">自定义title:</label>
                                    <div class="am-u-sm-9">
                                        <input type="text"autocomplete="off"  class="tpl-form-input" name="title" id="extraTitle"/>
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <label for="extraUrl" class="am-u-sm-3 am-form-label">自定义url:</label>
                                    <div class="am-u-sm-9">
                                        <input type="text"autocomplete="off"  class="tpl-form-input" name="title" id="extraUrl"/>
                                    </div>
                                </div>


                                <div class="am-form-group">

                                    <label class="am-u-sm-3 am-form-label">推送时间:

                                    </label>

                                    <div class="am-u-sm-9">
                                        <label for="radiopush0">
                                            <input type="radio" id="radiopush0" name="apps"  onclick="divClick();" value="1"/>
                                            <span>立即推送</span>
                                        </label>
                                        <label for="radiopush1">
                                            <input type="radio" id="radiopush1" name="apps" onclick="divClick();" value="2"/>
                                            <span>定时推送</span>
                                        </label>

                                        <div id="time" style="display: none;">
                                            <input class="Wdate "  autocomplete="off" readonly="readonly"  style="color: red;" id="startTime" name="startTime"
                                                   onFocus="WdatePicker({lang:'zh-cn',minDate:'%y-%M-%d 00:00:00',maxDate:'%y-%M-#{%d+3} 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss',position:{left:100,top:-15}})" />
                                            -至-
                                            <input class="Wdate " autocomplete="off" readonly="readonly" style="color: red;" id="expireTime" name="expireTime"
                                                   onFocus="WdatePicker({lang:'zh-cn',minDate:'#F{$dp.$D(\'startTime\')}',maxDate:'%y-%M-#{%d+3} 23:59:59',dateFmt:'yyyy-MM-dd HH:mm:ss',position:{left:100,top:-10}})" />
                                            在线设备可以接收到消息
                                        </div>

                                    </div>
                                </div>

                                <div class="am-form-group" style="text-align:center;line-height: 20px;">
                                    <div  >
                                        <button type="button" onclick="submitForm();" style="vertical-align:-100%"
                                                class="am-btn am-btn-primary tpl-btn-bg-color-success ">
                                            提交
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>



        </div>

    </div></div></body>
</html>